package com.huowei.htzy;

import android.content.Intent;
import android.os.Bundle;
import android.os.SystemClock;
import android.support.v7.app.AppCompatActivity;

import com.huowei.htzy.activity.GuideActivity;
import com.huowei.htzy.activity.HomeActivity;
import com.huowei.htzy.util.SharedUtils;

import java.util.Timer;
import java.util.TimerTask;

public class MainActivity extends AppCompatActivity {

    private SharedUtils utils;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        utils = SharedUtils.getInstance(this);
        //开启一延时器
        Timer timer = new Timer();
        timer.schedule(new TimerTask() {
            @Override
            public void run() {
                SystemClock.sleep(2000);
                if (!utils.getBoolean("flag")){
                    go2Welcome();
                    utils.putBoolean("flag",true);
                }else{
                    go2Home();
                }
            }
        },1000);
    }

    /**
     * 跳转主界面
     */
    private void go2Home() {
        startActivity(new Intent(this, HomeActivity.class));
        finish();
    }

    /**
     * 跳转欢迎界面
     */
    private void go2Welcome() {
        startActivity(new Intent(this, GuideActivity.class));
        finish();
    }
}
